#!/usr/bin/env python

VERSION = '1.0'
APPNAME = 'jni'

import os
import waf_dynamo
import waflib
import TestContext
from build_constants import TargetOS

test_context = None

def init(ctx):
    global test_context
    if 'build' in waflib.Options.commands:
        test_context = TestContext.create_test_context()

def options(opt):
    opt.load('waf_dynamo')

def configure(conf):
    conf.load('waf_dynamo')
    conf.load('java')
    conf.recurse('src')

    conf.env.append_unique('DEFINES', f'DLIB_LOG_DOMAIN="{APPNAME.upper()}"')

def build(bld):
    if not bld.env.IS_TARGET_DESKTOP:
        return
    bld.recurse('src')
    TestContext.initialize_test_context(test_context, bld)

    bld.install_files('${PREFIX}/lib/python', 'scripts/gen_java.py')
    bld.install_files('${PREFIX}/lib/python/external', 'scripts//external/gen_ir.py')
    bld.install_files('${PREFIX}/lib/python/external', 'scripts//external/gen_util.py')
    bld.install_files('${PREFIX}/include/jni', 'src/jni/jni_util.h')

def shutdown(self):
    waf_dynamo.run_tests(test_context, valgrind = True)
